<template>
  <div>
    <!--引入粒子特效-->
    <div class="bkpro-login-canvas">
      <Particles
        id="tsparticles"
        :particlesInit="particlesInit"
        :particlesLoaded="particlesLoaded"
        :options="options"
      />
      <div class="box">
        <div class="header">
          <nut-icon @click="goup" name="left"></nut-icon>登录
        </div>
        <div class="setion">
          <van-form @submit="onSubmit">
            <van-field
              v-model="username"
              name="用户名"
              label="用户名"
              placeholder="请输入用户名"
              :rules="[{ required: true, message: '请填写用户名' }]"
            />
            <van-field
              v-model="password"
              type="text"
              name="密码"
              label="密码"
              placeholder="请输入密码"
              :rules="[{ required: true, message: '请填写密码' }]"
            />
            <div style="margin: 16px">
              <van-button
                @click="Login"
                round
                block
                type="info"
                native-type="submit"
                >登录</van-button
              >
              <van-button @click="goreg" round block type="info"
                >注册</van-button
              >
            </div>
          </van-form>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent, reactive, UnwrapRef, ref } from "vue";
import router from "../../router";
import { api } from "../../api/api";
export default defineComponent({
  setup() {
    const options = {
      background: {
        color: {
          value: "#f4f5f6", //粒子颜色
        },
      },
      fpsLimit: 60,
      interactivity: {
        events: {
          onClick: {
            enable: true,
            mode: "push", //可用的click模式有: "push", "remove", "repulse", "bubble"。
          },
          onHover: {
            enable: true,
            mode: "grab", //可用的hover模式有: "grab", "repulse", "bubble"。
          },
          resize: true,
        },
        modes: {
          bubble: {
            distance: 400,
            duration: 2,
            opacity: 0.8,
            size: 40,
          },
          push: {
            quantity: 4,
          },
          repulse: {
            distance: 200,
            duration: 0.4,
          },
        },
      },
      particles: {
        color: {
          value: "#1677ff",
        },
        links: {
          color: "#1677ff", //'#dedede'。线条颜色。
          distance: 150, //线条长度
          enable: true, //是否有线条
          opacity: 0.5, //线条透明度。
          width: 1, //线条宽度。
        },
        collisions: {
          enable: false,
        },
        move: {
          direction: "none",
          enable: true,
          outMode: "bounce",
          random: false,
          speed: 2, //粒子运动速度。
          straight: false,
        },
        number: {
          density: {
            enable: true,
            area: 800,
          },
          value: 120, //粒子数量。
        },
        opacity: {
          value: 1, //粒子透明度。
        },
        shape: {
          type: "circle", //可用的粒子外观类型有："circle","edge","triangle", "polygon","star"
        },
        size: {
          random: true,
          value: 5,
        },
      },
      detectRetina: true,
    };
    const username = ref();
    const password = ref();
    function goreg() {
      router.push("/register");
    }
    function goup() {
      router.go(-1);
    }
    function Login() {
      const mound = { username: username.value, password: password.value };
      if (username.value != undefined && password.value != undefined) {
        api.getTest
          .gener(mound)
          .then((res: any) => {
            console.log(res);
          })
          .catch((err) => {
            localStorage.setItem("token", err.data.token);
            router.push("/first");
            console.log(err);
          });
      }
    }
    return {
      options,
      goreg,
      goup,
      Login,
      username,
      password,
    };
  },
});
</script>

<style lang="scss" scoped>
.box {
  width: 100%;
  height: 100px;
  position: fixed;
  .header {
    width: 100%;
    height: 50px;
    display: flex;
    background: #1ba9ba;
    justify-content: center;
    align-items: center;
    position: relative;
    font-weight: bold;
    color: white;
    font-size: 19px;
    .nutui-iconfont {
      position: absolute;
      left: 10px;
    }
  }
  .van-form {
    margin-top: 60px;
    .van-cell {
      height: 80px;
      display: flex;
      flex-direction: column;
      font-size: 16px;
    }
    .van-button {
      background: #1ba9ba;
      color: white;
      border: 0;
      height: 50px;
      margin-top: 20px;
      font-size: 18px;
    }
  }
}
</style>